package com.bh.common.utils;

import cn.hutool.extra.qrcode.QrCodeUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @Description
 * @Author slx
 * @Date 2024/3/26
 */
public class QrCodeUtils {
    public static String getQrCode(String code) {
        // buffer
        BufferedImage image = QrCodeUtil.generate(code, 200, 200);

        //输出流
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            ImageIO.write(image, "png", stream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "data:image/png;base64," + Base64.encode(stream.toByteArray());
    }

    public static void main(String[] args) {
        System.out.println(getQrCode("123"));
    }
}
